<?php
require(__META_CONTROLS_GEN__ . '/PersonMetaControlGen.class.php');




class PersonMetaControl extends PersonMetaControlGen {
    // Initialize fields with default values from database definition
    protected $txtOrg;
    protected $dttTime;

    public function __construct($objParentObject, Person $objPerson) {
        parent::__construct($objParentObject,$objPerson);
        if ( !$this->blnEditMode ) {
            $this->objPerson->Initialize();
        }
    }



    public function txtOrg_Create($strControlId = null) {
        $this->txtOrg = new QAjaxAutoCompleteTextBox($this->objParentObject, 'txtOrg_Change',$strControlId);
        $this->txtOrg->Name = QApplication::Translate('Organization');
        $this->txtOrg->MustMatch=true;
        if($this->objPerson->OrgId) $this->txtOrg->Text = $this->objPerson->Org->__toString();
        $this->txtOrg->MaxLength = Org::NameMaxLength;
        return $this->txtOrg;
    }


    public function calDob_Create($strControlId = null) {
        $this->calDob = new QCalendarPopup($this->objParentObject, $strControlId);
        $this->calDob->Name = QApplication::Translate('Date Of Birth');
        $this->calDob->DateTime = $this->objPerson->Dob;
        //$this->calDob->DateTimePickerType = QDateTimePickerType::Date;
        return $this->calDob;
    }


    public function SavePerson() {
        parent::SavePerson();

        try {
            if (strlen($this->txtOrg->Text) > 0) {
                $objOrg=Org::LoadByName($this->txtOrg->Text);
                $this->objPerson->OrgId = $objOrg->Id;
            }


            $this->dttTime = new QDateTime();
            $this->dttTime->setDate (date("Y"), date("m"), date("d"));
            $this->dttTime->setTime (date("H"), date("i"), date("s"));

            $CurrentUser = $_SESSION['User']['Id'];

            if ($this->blnEditMode) {
                //Updating
                $this->objPerson->UpdateDate = $this->dttTime;
                $this->objPerson->UpdateBy   = $CurrentUser;
            }
            else {
                //New
                $this->objPerson->CreateBy   = $CurrentUser;
                $this->objPerson->CreateDate = $this->dttTime;
            }
            //Save Record
            $this->objPerson->Save();


        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }
    }

}
?>